
<template>
  <el-row type="flex" justify="center" align="middle" class="loginBox">
    <el-col class="formBox" :span="12">
      <el-form :model="ruleForm" :rules="rules" ref="form" label-width="80px">
        <el-form-item label="手机号" prop="moduil">
          <el-input v-model="ruleForm.moduil"></el-input>
        </el-form-item>
        <el-form-item label="验证码" prop="phone">
          <el-input v-model="ruleForm.phone"></el-input>
        </el-form-item>
        <!-- 特别说明 -->

        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>
export default {
  data () {
    // 定义 自定义校验函数（复杂校验）
    // rule:校验规则
    // value:表单项输入的值
    // callback：（函数）决定是否通过校验 校验失败，调用callback（new Error('错误说明)）
    //
    const validateMobile = (rule, value, callback) => {
      if (!/^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/.test(value)) {
        callback(new Error('手机号格式不对！'))
      } else {
        callback()
      }
    }
    return {
      ruleForm: {
        moduil: '',
        phone: ''

      },
      // 校验规则的属性名和要校验的表单数据的属性名一模一样
      rules: {
        moduil: [
          // blur 鼠标失去焦点开始校验
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          { validator: validateMobile, trigger: 'blur' }
        ],
        // change 一遍输入一边校验
        phone: [
          { required: true, message: '请输入活动名称', trigger: 'change' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    async onSubmit () {
      try {
        await this.$refs.form.validate()
        console.log('登录', this.ruleForm)
        this.$router.push('/home')
      } catch (e) {
        console.log(e)
      }
    },
    // 重置
    reset () {
      this.ruleForm.other = ''
      this.$refs.form.resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.loginBox {
  width: 100vw;
  height: 100vh;

  background-image: radial-gradient(
      circle at 67% 83%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 1%,
      transparent 1%,
      transparent 5%,
      transparent 5%,
      transparent 100%
    ),
    radial-gradient(
      circle at 24% 80%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 27%,
      transparent 27%,
      transparent 63%,
      transparent 63%,
      transparent 100%
    ),
    radial-gradient(
      circle at 23% 5%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 26%,
      transparent 26%,
      transparent 82%,
      transparent 82%,
      transparent 100%
    ),
    radial-gradient(
      circle at 21% 11%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 35%,
      transparent 35%,
      transparent 45%,
      transparent 45%,
      transparent 100%
    ),
    radial-gradient(
      circle at 10% 11%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 21%,
      transparent 21%,
      transparent 81%,
      transparent 81%,
      transparent 100%
    ),
    radial-gradient(
      circle at 19% 61%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 20%,
      transparent 20%,
      transparent 61%,
      transparent 61%,
      transparent 100%
    ),
    radial-gradient(
      circle at 13% 77%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 63%,
      transparent 63%,
      transparent 72%,
      transparent 72%,
      transparent 100%
    ),
    radial-gradient(
      circle at 30% 93%,
      hsla(317, 0%, 96%, 0.05) 0%,
      hsla(317, 0%, 96%, 0.05) 33%,
      transparent 33%,
      transparent 82%,
      transparent 82%,
      transparent 100%
    ),
    linear-gradient(90deg, rgb(22, 176, 207), rgb(103, 7, 215));
  .formBox {
    border-radius: 20px;
    padding: 20px;
    background: #fff;
  }
}
</style>
